<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'mortgage.label', default: 'Mortgage')}"/>
    <title>其他权利质押品</title>
    <style>
    .table>tbody>tr>td{
        vertical-align: middle;
    }
    @media screen and (min-width:1900px) and (max-width:1920px) {
        .flex{
            display: flex;justify-content: center;align-items: center;
        }
    }
    .select2-container .select2-choices .select2-search-field input,.select2-container .select2-choice,.select2-container .select2-choices{

        color: #999;
    }
    </style>
</head>

<body class="fixed-navbar fixed-sidebar">

<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right navFloatRight">
                <ol class="hbreadcrumb breadcrumb">
                    <li>
                        <span>CINDATA PLS</span>
                    </li>
                    <li class="active">
                        <span>其他权利质押品</span>
                    </li>
                </ol>
            </div>
        </div>
    </div>
</div>

<div class="content animate-panel">
    <div class="row">
        <g:form method="POST" controller="otherCollateral" action="index" class="form-horizontal" role="form" id="form">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <button class="btn btn-primary btn-xs" type="submit" onclick="text()"><i class="fa fa-search"></i> 查询</button>
                        <button class="btn btn-warning2 btn-xs" type="button" id="resetBtn">
                            <i class="fa fa-times"></i> 重置</button>
                    </div>
                    查询
                </div>

                <div class="panel-body seach-group" id="bug1">
                <div class="row flex">
                    <div class="form-group col-sm-4">
                        <label for="city" class="col-sm-3 control-label">城市</label>
                        <div class="col-sm-9">
                            <g:select class="form-control" name="city" id="city" from="${com.cindata.City.findAllByNameInList(new com.cindata.ComponentService().evaluate(com.cindata.Component.findByCode('showCity')), [sort: 'name', order: 'asc'])}" optionKey="id" optionValue="name" value="${params?.city}"
                                    noSelection="${['': '请选择城市']}"/>
                        </div>
                    </div>
                    <div class="form-group col-sm-4">
                        <label class="col-sm-3 control-label" for="loansDuration">押品风险</label>
                        <div class="col-sm-9">
                            <g:select class="form-control" name="risk" id="risk" from="${com.cindata.dimension.RiskDimension.list()}" optionKey="label" optionValue="label"
                                    value="${params?.risk}" noSelection="${['': '请选择押品风险']}"/>
                        </div>
                    </div>
                    <div class="form-group col-sm-4">
                        <label class="col-sm-3 control-label">押品状态</label>
                        <div class="col-sm-9">
                            <g:select class="form-control" name="estateStatus" id="estateStatus" from="${com.cindata.dictionary.EstateStatusDict.list()}" optionKey="id" optionValue="name" value="${params?.estateStatus}"
                                    noSelection="${['': '请选择押品状态']}"/>
                        </div>
                    </div>
                </div>
                
                <div class="row flex">
                    <div class="form-group col-sm-4">
                        <label class="col-sm-3 control-label">质押品类型</label>
                        <div class="col-sm-9">
                            <g:select class="form-control" name="type" id="type" from="${com.cindata.dictionary.OtherCollateralTypeDict.list()}" optionKey="id" optionValue="name" value="${params?.type}" noSelection="${['': '请选择质押品类型']}"/>
                        </div>
                    </div>

                    <div class="form-group col-sm-4">
                        <label for="district" class="col-sm-3 control-label">质押品名称</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="name" id="name" value="${params?.name}" placeholder="请输入质押品名称">
                        </div>
                    </div>
                    <div class="form-group col-sm-4">
                        <label class="col-sm-3 control-label">变现能力</label>
                        <div class="col-sm-9">
                            <g:select class="form-control" name="cashability" id="cashability" from="${com.cindata.dictionary.Cashability.list()}" optionKey="id" optionValue="name" value="${params?.cashability}"
                                    noSelection="${['': '请选择变现能力']}"/>
                        </div>
                    </div>
                </div>

                <div class="row flex">
                    <div class="form-group col-sm-4 hidden" id="rightsTypeDiv">
                        <label class="col-sm-3 control-label">知识产权类型</label>
                        <div class="col-sm-9">
                            <g:select class="form-control m-b" name="rightsType" id="rightsType" from="${com.cindata.dictionary.ManagementRightsType.list()}" optionValue="name" optionKey="id" noSelection="${['': '请选择知识产权']}" value="${params?.rightsType}"/>
                        </div>
                    </div>

                    <div class="form-group col-sm-4" id="seizeDiv">
                    </div>
                    
                    <div class="form-group col-sm-4" id="seizeDiv">
                    </div>

                    <div class="form-group col-sm-4">
                    </div>
                </div>
            </div>
        </g:form>
    </div>
    </div>

    <div class="row">
        <div class="hpanel hgreen">
            <div class="panel-heading">
                <div class="panel-tools">
                    <g:link action="create" class="btn btn-info btn-xs"><i class="fa fa-plus"></i>新建</g:link>
                    <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                </div>
                全部押品
            </div>
            <div class="panel-body no-padding">
                <div class="table-responsive">
                    <table cellpadding="1" cellspacing="1" class="table table-striped table-bordered table-hover text-center" id="esateTable">
                        <thead>
                        <tr>
                            <th style="width: 60px;"><input type="checkbox" class="i-checks allCheckbox" id="allOptionId"></th>
                            <g:sortableColumn property="externalId" title="质押品编号" class="text-center" params="${params}"/>
                            <g:sortableColumn property="type" title="质押品类型" class="text-center" params="${params}"/>
                            <g:sortableColumn property="estateStatus" title="押品状态" class="text-center" params="${params}"/>
                            <g:sortableColumn property="name" title="质押品名称" class="text-center" params="${params}"/>
                            <g:sortableColumn property="city" title="城市" class="text-center" params="${params}"/>
                            <g:sortableColumn property="fullName" title="出质人名称" class="text-center" params="${params}"/>
                            <g:sortableColumn property="commonOwnerFullName" title="其他共同所有人"  class="text-center" params="${params}"/>
                            <g:sortableColumn property="registerFullName" title="登记人" class="text-center"  params="${params}"/>
                            <g:sortableColumn property="registerAccount" title="登记机构" class="text-center" params="${params}"/>
                            <g:sortableColumn property="registerDate" title="登记日期" class="text-center" params="${params}"/>
                            <g:sortableColumn property="cashability" title="变现能力" class="text-center" params="${params}"/>
                            <g:sortableColumn property="latestEvaluatePrice" title="最新评估价值"   params="${params}"/>
                            <g:sortableColumn property="latestEvaluateDate" title="最新评估日期"   params="${params}"/>
                            <g:sortableColumn property="risk" title="押品风险" class="text-center" params="${params}"/>
                            <th style="color: #34495e;">操作项</th>
                        </tr>
                        </thead>
                        <tbody>
                        <g:each in="${collateralList}">
                        <tr>
                            <td><input type="checkbox" class="i-checks everyCheckbox" name="everyCheckbox" value="${it?.id}"></td>
                            <td ><g:link style="color: #3498DB" class="firstTd" action="show" id="${it?.id}">${it?.externalId}</g:link></td>
                            <td><g:if test="${it?.otherCollateral?.rightsType?.name}">${it?.otherCollateral?.rightsType?.name}</g:if><g:else>${it?.otherCollateral?.type?.name}</g:else></td>
                            <td>${it?.estateStatus?.name}</td>
                            <td>${it?.name}</td>
                            <td>${it?.city?.name}</td>
                            <td>${it?.fullName}</td>
                            <td>${it?.commonOwnerFullName}</td>
                            <td>${it?.registerFullName}</td>
                            <td>${it?.registerAccount}</td>
                            <td>${it?.registerDate}</td>
                            <td>${it?.cashability?.name}</td>
                            <td>${it?.latestEvaluatePrice}</td>
                            <td>
                                <g:if test="${it?.latestEvaluateDate}">
                                    <g:formatDate date="${it?.latestEvaluateDate}" format="yyyy-MM-dd"></g:formatDate>
                                </g:if>
                            </td>
                            <td>
                                <g:if test="${it?.cltv>=0&&it?.cltv<=0.6}">低</g:if>
                                <g:if test="${it?.cltv>0.6&&it?.cltv<=0.8}">中</g:if>
                                <g:if test="${it?.cltv>0.8&&it?.cltv<=1}">高</g:if>
                                <g:if test="${it?.cltv>1}">损失</g:if>
                            </td>
                            <td>
                                <div style="margin-bottom: 2px;">
                                    <a href="${it?.id}" class="btn btn-xs btn-outline btn-success handleButton">
                                        评估
                                    </a>
                                </div>
                            </td>
                        </tr>
                        </g:each>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="panel-footer">
                <div class="pagination">
                    <g:paginate action="index" total="${collateralCount ?: 0}" params="${params}"/>
                </div>
                <div style="display: flex;justify-content: center;">
                    <button type="button" class="btn w-xs btn-success warningButton">批量评估</button>
                    <button type="button" class="btn w-xs btn-default cancelButton" style="margin-left: 20px;">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>

<g:javascript>
    var checkAll =$('.allCheckbox');  //全选的input
    var checkboxs =$('.everyCheckbox'); //所有单选的input

    checkAll.on('ifChecked ifUnchecked',function(event){
        if(event.type == 'ifChecked'){
            checkboxs.iCheck('check');
        }else{
            checkboxs.iCheck('uncheck');
        }
    });

    checkboxs.on('ifChanged',function(event){
        if(checkboxs.filter(':checked').length == checkboxs.length){
            checkAll.prop('checked',true);
        }else{
            checkAll.prop('checked',false);
        }
        checkAll.iCheck('update');
    });
    //单条评估
    $(".handleButton").click(function(event){
        event.preventDefault();
        var id = $(this).attr("href");
        swal({
            title: "确定评估该押品吗？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: true
        },
                function(){
                    $.ajax({
                        url:'/valuationHistory/evaluate',
                        data:{
                            ids:id,
                            sourceClass: 'otherCollateral'
                        },
                        type:"post",
                        success:function(data)
                        {
                            if(data.status=="success"){
                                window.location.href="/otherCollateral/index"
                            }else{
                                swal("评估失败，请稍后重试", "", "error");
                            }
                        }
                    })

                });
    });
    //多条评估
    $(".warningButton").click(function(){
        var ids = $("input:checkbox[name='everyCheckbox']:checked").map(function(index,elem) {
            return $(elem).val();
        }).get().join(',');
        if(!ids){
            toastr.error('请选择押品！');
            return
        }
        swal({
            title: "确定评估该押品吗？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: true
        },
                function(){
                    $.ajax({
                        url:'/valuationHistory/evaluate',
                        data:{
                            ids:ids,
                            sourceClass: 'otherCollateral'
                        },
                        type:"post",
                        success:function(data)
                        {
                            if(data.status=="success"){
                                window.location.href="/otherCollateral/index"
                            }else{
                                swal("评估失败，请稍后重试", "", "error");
                            }
                        }
                    })
                });
    });
    //取消按钮事件
    $(".cancelButton").click(function(){
        checkboxs.iCheck('uncheck');
    });
    function searchMap() {
        var risk=$("#risk").val(),
                city=$('#zoneNumber').val(),
                district=$('#district').val(),
                precinct=$('#precinct').val(),
                inputData={
                    risk:risk,
                    zoneNumber:city,
                    district:district,
                    precinct:precinct
                };
        if(city=="-1"){
            toastr.error('请选择城市');
            return
        }
        window.location.href="/newMap/cluster?currentMap=clusterMap&city="+$("#city").val()+"&district="+$("#district").val()+"&communityId="+$("#communityId").val();
    }
    function show(id){
        var url = window.location.origin+"/otherCollateral/show?id="+id;
        window.open(url);
    }
    
    function create(){
        var url = window.location.origin+"/otherCollateral/create"
        window.open(url)
    }

    $(function () {
        $('#datepicker').datepicker({
            language: 'zh-CN'
        });
        $("#datepicker").on("changeDate", function(event) {
            $("#my_hidden_input").val(
                    $("#datepicker").datepicker('getFormattedDate')
            )
        });

        $('.input-group.date').datepicker({ });
        $('.input-daterange').datepicker({ });
    });

    //重置按钮
    $("#resetBtn").click(function () {
        $("#city").val("");
        $("#s2id_city span:first").html("请选择城市");
        $('#risk').val("");
        $("#s2id_risk span:first").html("请选择押品风险");
        $('#estateStatus').val("");
        $("#s2id_estateStatus span:first").html("请选择押品状态");
        $('#name').val("");
        $('#mortgageStatus').val("");
        $("#s2id_mortgageStatus span:first").html("请选择贷款状态");
        $('#cashability').val("");
        $("#s2id_cashability span:first").html("请选择变现能力");
        $('#type').val("");
        $("#s2id_type span:first").html("请选择质押品类型");
        $('#rightsType').val("");
        $("#s2id_rightsType span:first").html("请选择知识产权类型");
    });

    $("#type").change(function () {
        if ($("#type option:selected").text() == "知识产权") {
            $("#rightsTypeDiv").removeClass("hidden");
            $("#seizeDiv").addClass("hidden");
        } else {
            $("#rightsTypeDiv").addClass("hidden");
            $("#seizeDiv").removeClass("hidden");
            $('#rightsType').val("");
            $("#s2id_rightsType span:first").html("请选择知识产权类型");
        }
    });
    if ('${params.rightsType}')
    {
        $("#rightsTypeDiv").removeClass("hidden");
        $("#seizeDiv").addClass("hidden");
    }
    else
    {
        $("#rightsTypeDiv").addClass("hidden");
        $("#seizeDiv").removeClass("hidden");
    }
</g:javascript>

</body>
</html>
